﻿using Microsoft.AspNetCore.Authorization;

namespace Wenyu.Framework.WebCore.AuthorizationExtend
{
    public class MenuAuthorizationHandler : AuthorizationHandler<MenuAuthorizationRequirement>
    {
        protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, MenuAuthorizationRequirement requirement)
        {
            if (context.User.Claims == null||context.User.Claims.Count()<=0)
            {
                context?.Fail();

            }else if (context.User.IsInRole("admin"))
            {
                context?.Succeed(requirement);
            }
            await Task.CompletedTask;
        }
    }
}
